package com.joplus.housekeeper.ui.view.joExpendPopWindow;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;


/**
 * Created by Administrator on 2016/9/23.
 */
public class ExpendPopWindow {



    PopupWindow popupWindow;
    BasePopWindowAdapter madapter;
    Context mcontext;

    public ExpendPopWindow(Context context, View parent, BasePopWindowAdapter adapter) {
        if (adapter == null) {
            return;
        }
        mcontext = context;
        madapter = adapter;
        init(parent, madapter);
    }

    public boolean isShowing() {
        return popupWindow != null && popupWindow.isShowing();
    }


    public void setAdapter() {

    }

    private void init(View parent, BasePopWindowAdapter adapter) {
        popupWindow = new PopupWindow();
        //popupWindow.setAnimationStyle(R.style.city_select_anim);
        popupWindow.setContentView(adapter.getView());
        popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        // 设置PopupWindow弹出软键盘模式（此处为覆盖式）
        popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.showAsDropDown(parent);

        parent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                dismiss();
                return false;
            }
        });
        int[] location = new int[2];


    }

    public void setDissmissListener(PopupWindow.OnDismissListener listener) {
        popupWindow.setOnDismissListener(listener);
    }


    public void dismiss() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            popupWindow = null;

        }
    }

    //popwindow 内部点击事件的回调接口
    public interface onClickListener {
        public void onclick(String s, View view);
    }


    public interface MeausShowListener {
        public void isShow(Boolean showing);
    }


}
